<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$_SESSION['uid']=$_SESSION['uid']?:0;
if($_RQ['op']=='main'){
	//返回链接
	$return['forward_url']=base64_encode('jy_ailiao/msglog/');
	$return['params']=array('type'=>intval($_RQ['type']));
	$return['list']=array();
	$return['ping']=$this->plugin_setting('ping');
	if($return['ping']['isclose']){
		$return['params']['type']=3;
	}
	$return['pcd']=$this->session('pcd')?:array('city'=>'');
	set_html('title','消息列表');
	exi($return);
}
// js 获取数据
if($_RQ['op']=='getlist'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$type=intval($_RQ['type']);
	if($type==1){
		$params['mid']=$_SESSION['uid'];
		$table='jy_ailiao_msglog';
	}elseif($type==3){
		$params['mid OR']='mid='.$_SESSION['uid'].' or tomid='.$_SESSION['uid'];
		$table='jy_ailiao_tcp';
	}else{
		if($type==2){
			$params['mid']=$_SESSION['uid'];
		}else{
			$params['tomid']=$_SESSION['uid'];
		}
		$table='jy_ailiao_pinglog';
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	//print_r($params);exit;
	$list=pdo_getslice($table,$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	$lat_lng=$this->session('lat_lng');
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	foreach($list as $k=>&$item){
		if($type!=1){
			if($type==2){
				$mid=$item['tomid'];
			}else{
				$mid=$item['mid'];
			}
			if($type==3){
				$mid=$mid==$_SESSION['uid']?$item['tomid']:$mid;
				if($item['tomid']==$item['mid']){
					unset($list[$k]);
				}
			}
			if($type==3){
				$item['noread']=pdo_count('jy_ailiao_tcplog',array('isread'=>0,'tcpid'=>$item['id'],'uniacid'=>$_SESSION['uniacid'],'tomid'=>$_SESSION['uid']));
				$tcplog=pdo_get('jy_ailiao_tcplog',array('tcpid'=>$item['id'],'uniacid'=>$_SESSION['uniacid'],'tomid'=>$_SESSION['uid']),array('type','msg'),'createtime desc');
				$item['msgtype']=$tcplog['type'];
				if(!$tcplog['type']){
					$item['desc']=$tcplog['msg'];
				}elseif($tcplog['type']==4){
					$item['desc']='图片';
				}elseif($tcplog['type']==7){
					$item['desc']='文件';
				}elseif($tcplog['type']==8){
					$item['desc']='商品';
				}
			}
			$member=pdo_get('jy_ailiao_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$mid),array('id','mid','avatar','nickname','city','lat_lng','birth','sex','zhiwei','height','star','paixu','status'));
			$member['birth']=json_decode($member['birth'],true);
			$member['age'] = $member['birth']['year']?$current_year - $member['birth']['year'] - 1:'**';
			$member['height']=$this->heights[$member['height']];
			$member['zhiwei']=$zhiweis[$member['zhiwei']];
			$member['lat_lng']=json_decode($member['lat_lng'],true);
			if($member['lat_lng']['lng'] && $member['lat_lng']['lat']){
				$member['juli']=cfc('tools')->getdistance($lat_lng['lng'],$lat_lng['lat'],$member['lat_lng']['lng'],$member['lat_lng']['lat']);
				$member['juli']=$member['juli']?price($member['juli']/1000,'int'):0;
			}else{
				$member['juli']=0;
			}
			$item['member']=$member;
		}
		if($type==3){
			if($item['createtime']>$daytime){
				$item['createtime']=date('H:i',$item['createtime']);
			}else{
				$item['createtime']=date('m-d',$item['createtime']);
			}
		}else{
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
		}
		$item['statustitle']=$this->jilog_status[$item['status']];
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='nodian'){
	$logid=$_RQ['id'];
	pdo_update('jy_ailiao_pinglog',array('status'=>2,'looktime'=>time()),array('id'=>$logid));
	$log=$this->get('pinglog',array('id'=>$logid,'uniacid'=>$_SESSION['uniacid']));
	$this->update('member',array('pingnum +='=>1),array('mid'=>$log['mid'],'uniacid'=>$_SESSION['uniacid']));
	exi('操作成功！','','main');
}
if($_RQ['op']=='yuered'){
	$logid=$_RQ['id'];
	$this->model('ping')->checkping();
	pdo_update('jy_ailiao_pinglog',array('status'=>3,'looktime'=>time()),array('id'=>$logid));
	$this->model('worker')->yuered($logid);
	exi('操作成功！','','main');
}
if($_RQ['op']=='nodian2'){
	$logid=$_RQ['id'];
	pdo_update('jy_ailiao_tcp',array('status'=>2,'looktime'=>time()),array('id'=>$logid));
	exi('操作成功！','','main');
}
if($_RQ['op']=='yuered2'){
	$logid=$_RQ['id'];
	pdo_update('jy_ailiao_tcp',array('status'=>3,'looktime'=>time()),array('id'=>$logid));
	exi('操作成功！','','main');
}
?>